home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / fontutil.6 / fontutil / fontutils-0.6 / tfm / fontdimen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-12  |  6.3 KB  |  184 lines

  1. /* fontdimen.c: handle TFM fontdimens a.k.a. font parameters.
  2.  
  3. Copyright (C) 1992 Free Software Foundation, Inc.
  4.  
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. #include "config.h"
  20.  
  21. #include "tfm.h"
  22.  
  23.  
  24. /* This structure maps font parameter names to numbers.  */
  25. typedef struct
  26. {
  27.   string name;
  28.   unsigned number;
  29. } font_param_type;
  30.  
  31. /* The list of fontdimen names and their corresponding numbers.  I wish
  32.    I could figure out a good way to give this list only once (in tfm.h),
  33.    instead of three times.  */
  34.  
  35. static font_param_type font_param[] = {
  36.   { "slant",            TFM_SLANT_PARAMETER },
  37.   { "space",            TFM_SPACE_PARAMETER },
  38.   { "stretch",            TFM_STRETCH_PARAMETER },
  39.   { "shrink",            TFM_SHRINK_PARAMETER },
  40.   { "xheight",            TFM_XHEIGHT_PARAMETER },
  41.   { "quad",            TFM_QUAD_PARAMETER },
  42.   { "extraspace",        TFM_EXTRASPACE_PARAMETER },
  43.   { "num1",            TFM_NUM1_PARAMETER },
  44.   { "num2",            TFM_NUM2_PARAMETER },
  45.   { "num3",            TFM_NUM3_PARAMETER },
  46.   { "denom1",            TFM_DENOM1_PARAMETER },
  47.   { "denom2",            TFM_DENOM2_PARAMETER },
  48.   { "sup1",            TFM_SUP1_PARAMETER },
  49.   { "sup2",            TFM_SUP2_PARAMETER },
  50.   { "sup3",            TFM_SUP3_PARAMETER },
  51.   { "sub1",            TFM_SUB1_PARAMETER },
  52.   { "sub2",            TFM_SUB2_PARAMETER },
  53.   { "supdrop",            TFM_SUPDROP_PARAMETER },
  54.   { "subdrop",            TFM_SUBDROP_PARAMETER },
  55.   { "delim1",            TFM_DELIM1_PARAMETER },
  56.   { "delim2",            TFM_DELIM2_PARAMETER },
  57.   { "axisheight",        TFM_AXISHEIGHT_PARAMETER },
  58.   { "defaultrulethickness",    TFM_DEFAULTRULETHICKNESS_PARAMETER },
  59.   { "bigopspacing1",        TFM_BIGOPSPACING1_PARAMETER },
  60.   { "bigopspacing2",        TFM_BIGOPSPACING2_PARAMETER },
  61.   { "bigopspacing3",        TFM_BIGOPSPACING3_PARAMETER },
  62.   { "bigopspacing4",        TFM_BIGOPSPACING4_PARAMETER },
  63.   { "bigopspacing5",        TFM_BIGOPSPACING5_PARAMETER },
  64.   { "leadingheight",        TFM_LEADINGHEIGHT_PARAMETER },
  65.   { "leadingdepth",        TFM_LEADINGDEPTH_PARAMETER },
  66.   { "fontsize",            TFM_FONTSIZE_PARAMETER },
  67.   { "version",            TFM_VERSION_PARAMETER },
  68. };
  69.  
  70. /* Set the font parameter entries in TFM_INFO according to the string S.
  71.    If S is non-null and non-empty, it should look like
  72.    <fontdimen>:<real>,<fontdimen>:<real>,..., where each <fontdimen> is
  73.    either a standard name or a number between 1 and 30 (the 30 comes
  74.    from the default value in PLtoTF, it's not critical).  
  75.  
  76.    Also, if the `design_size' member of TFM_INFO is nonzero, we set the
  77.    `FONTSIZE' parameter to 1.0 (meaning it's equal to the design size),
  78.    unless the `FONTSIZE' parameter is already set.  */
  79.    
  80. void
  81. tfm_set_fontdimens (string s, tfm_global_info_type *tfm_info)
  82. {
  83.   string spec;
  84.   
  85.   /* If S is empty, we have nothing more to do.  */
  86.   if (s == NULL || *s == 0)
  87.     return;
  88.   
  89.   /* Parse the specification string.  */
  90.   for (spec = strtok (s, ","); spec != NULL; spec = strtok (NULL, ","))
  91.     {
  92.       string fontdimen;
  93.       real value;
  94.       unsigned param_number = 0;
  95.       string value_string = strchr (spec, ':');
  96.       
  97.       if (value_string == NULL || !float_ok (value_string))
  98.         FATAL1 ("Fontdimens look like `<fontdimen>:<real>', not `%s'",
  99.                 spec);
  100.  
  101.       value = atof (value_string + 1);
  102.       fontdimen = substring (spec, 0, value_string - spec - 1);
  103.       
  104.       /* If `fontdimen' is all numerals, we'll take it to be an integer.  */
  105.       if (strspn (fontdimen, "0123456789") == strlen (fontdimen))
  106.         {
  107.           param_number = atou (fontdimen);
  108.  
  109.           if (param_number == 0 || param_number > TFM_MAX_FONT_PARAMETERS)
  110.             FATAL2 ("Font parameter %u is not between 1 and the maximum (%u)",
  111.                     param_number, TFM_MAX_FONT_PARAMETERS);
  112.         }
  113.       else
  114.         { /* It wasn't a number; see if it's a valid name.  */
  115.       param_number = tfm_fontdimen_number (fontdimen);
  116.  
  117.       if (param_number == 0)
  118.             FATAL1 ("I don't know the font parameter name `%s'", fontdimen);
  119.         }
  120.       
  121.       /* If we got here, `param_number' is the number of the font
  122.          parameter we are supposed to assign to.  */
  123.       tfm_set_font_parameter (param_number, value, tfm_info);
  124.       
  125.       /* If `param_number' is past the last fontdimen previously
  126.          assigned, we have to assign zero to all the intervening ones.
  127.          But this can never happen, because we always assign the
  128.          `fontsize' parameter, which happens to be the last one.  */
  129.       assert (param_number <= TFM_FONT_PARAMETER_COUNT (*tfm_info));
  130.     }
  131. }
  132.  
  133. /* Return zero if we do not recognize S as the name of a fontdimen, else
  134.    its corresponding number.  We just do a linear search through the
  135.    structure, since it's so small.  */
  136.  
  137. unsigned
  138. tfm_fontdimen_number (string s)
  139. {
  140.   unsigned this_param;
  141.   unsigned param_number = 0;
  142.  
  143.   for (this_param = 0;
  144.        this_param < TFM_MAX_FONT_PARAMETERS && param_number == 0;
  145.        this_param++)
  146.     if (STREQ (s, font_param[this_param].name))
  147.       param_number = font_param[this_param].number;
  148.  
  149.   return param_number;
  150. }
  151.  
  152. /* Set the PARAMETER-th font parameter of TFM_INFO to VALUE.  If
  153.    PARAMETER is beyond the current last parameter of TFM_INFO, set
  154.    all the intervening parameters to zero.  */
  155.  
  156. void
  157. tfm_set_fontdimen (tfm_global_info_type *tfm_info,
  158.                    unsigned parameter, real value, 
  159. {
  160.   if (TFM_FONT_PARAMETER_COUNT (*tfm_info) < parameter)
  161.     {
  162.       unsigned p;
  163.       
  164.       for (p = TFM_FONT_PARAMETER_COUNT (*tfm_info) + 1; p < parameter; p++)
  165.         TFM_FONT_PARAMETER (*tfm_info, p) = 0.0;
  166.       
  167.       /* Now we have more parameters.  */
  168.       TFM_FONT_PARAMETER_COUNT (*tfm_info) = parameter;
  169.     }
  170.  
  171.   TFM_FONT_PARAMETER (*tfm_info, parameter) = value;
  172. }
  173.  
  174.  
  175. /* Set the `FONTSIZE' parameter of TFM_INFO, if the design size is set.  */
  176.  
  177. void
  178. tfm_set_fontsize (tfm_global_info_type *tfm_info)
  179. {
  180.   if (TFM_DESIGN_SIZE (*tfm_info) != 0.0)
  181.     tfm_set_font_parameter (TFM_FONTSIZE_PARAMETER, 
  182.                 TFM_DESIGN_SIZE (*tfm_info), tfm_info);
  183. }
  184.